package org.dizena.auth.starter.web;

import lombok.extern.slf4j.Slf4j;
import org.dizena.auth.starter.entity.User;
import org.dizena.common.base.enums.EnumHeaderKey;
import org.dizena.common.interaction.response.NoResultVOAdvice;
import org.dizena.common.utils.ReqUtil;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/auth")
public class AuthController {
    @GetMapping({"/test"})
    public User test() throws InterruptedException {
        Map<String, String> header = ReqUtil.getHeaderMap();
        log.info("header tid={},sid={}", header.get(EnumHeaderKey.TRACE_ID.getKey()), header.get("sid"));
        User user = new User();
        user.setId(1L);
        user.setName(header.get("uid"));
        user.setAge(32);
        log.info("auth test {}", user);
        return user;
    }

    @GetMapping({"/get"})
    @NoResultVOAdvice
    public User get() throws InterruptedException {
        Map<String, String> header = ReqUtil.getHeaderMap();
        log.info("header tid={},sid={}", header.get(EnumHeaderKey.TRACE_ID.getKey()), header.get("sid"));
        User user = new User();
        user.setId(1L);
        user.setName(header.get("uid"));
        user.setAge(32);
        log.info("get test {}", user);
        return user;
    }

    @PostMapping({"/post"})
    //@NoResultVOAdvice
    public User post(@RequestBody User user) throws InterruptedException {
        Map<String, String> header = ReqUtil.getHeaderMap();
        log.info("header tid={},sid={}", header.get(EnumHeaderKey.TRACE_ID.getKey()), header.get("sid"));
        log.info("post test {}", user);
        return user;
    }


}
